package com.example.my.shop.mybatis.service.impl;

import com.example.my.shop.mybatis.dao.TbUserMapper;
import com.example.my.shop.mybatis.entity.TbUser;
import com.example.my.shop.mybatis.service.TbUserService;
import com.example.my.shop.mybatis.utils.MybatisUtils;
import org.apache.ibatis.session.SqlSession;

import java.util.List;
import java.util.Map;

public class TbUserServiceImpl implements TbUserService {

    SqlSession sqlSession = MybatisUtils.getSqlSession();
    TbUserMapper tbUserMapper = sqlSession.getMapper(TbUserMapper.class);


    @Override
    public TbUser selectEmailAndPassWord(String email) {
        return tbUserMapper.selectEmailAndPassWord(email);
    }

    @Override
    public List<TbUser> findAll() {
        return tbUserMapper.findAll();
    }

    @Override
    public boolean addUser(TbUser tbUser) {
        boolean b = tbUserMapper.addUser(tbUser);
        sqlSession.commit();
        return b;
    }

    @Override
    public int deleteById(Long id) {
        int i = tbUserMapper.deleteById(id);
        sqlSession.commit();
        return i;
    }

    @Override
    public int updateTbUer(TbUser tbUser) {
        int i = tbUserMapper.updateTbUer(tbUser);
        sqlSession.commit();
        return i;
    }

    @Override
    public TbUser findById(Long id) {
        return tbUserMapper.findById(id);
    }

    @Override
    public int batchDelete(String[] ids) {
        int i = tbUserMapper.batchDelete(ids);
        sqlSession.commit();
        return i;
    }

    @Override
    public List<TbUser> likeSearch(Map map) {
        return tbUserMapper.likeSearch(map);
    }
}
